﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;


namespace IHISCETeim.Web.MachineSys.MacModel
{
    public partial class VINList : PageBase
    {
        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.查看, Permission.修改, Permission.新增, Permission.删除 };
            }
        }
        protected override string DWZRef
        {
            get
            {
                return "VINList";
            }
        }

        protected string SerialNumber
        {
            get
            {
                return GetRequestValue<string>("SerialNumber", "");
            }
        }
        protected string MacType
        {
            get
            {
                return GetRequestValue<string>("MacType", "");
            }
        }
        protected string AddDateFrom
        {
            get
            {
                return GetRequestValue<string>("AddDateFrom", "");
            }
        }

        protected string AddDateTo
        {
            get
            {
                return GetRequestValue<string>("AddDateTo", "");
            }
        }
        protected string SCDATEFrom
        {
            get
            {
                return GetRequestValue<string>("SCDATEFrom", "");
            }
        }

        protected string SCDATETo
        {
            get
            {
                return GetRequestValue<string>("SCDATETo", "");
            }
        }

        protected override string orderField
        {
            get
            {
                return string.IsNullOrEmpty(base.orderField) ? "ID" : base.orderField;
            }
        }
        /// <summary>
        /// 当前排序方式
        /// </summary>
        protected override string orderDirection
        {
            get
            {
                return string.IsNullOrEmpty(base.orderDirection) ? "Desc" : base.orderDirection;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            DataBind();
        }

        protected void DataBind()
        {

            this.rpMenu.DataSource = VINController.GetPagination(GetSql(), pageNum, numPerPage, SQLSort, ref TotalCount);
            this.rpMenu.DataBind();
        }

        protected string GetSql()
        {
            string wheresql = "";

            string ItemCodeSQL = "";
            if (!string.IsNullOrEmpty(SerialNumber))
            {
                ItemCodeSQL = string.Format(" (SerialNumber like '%{0}%') ", SerialNumber);
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + ItemCodeSQL;
                }
                else
                {
                    wheresql = ItemCodeSQL;
                }
            }

            if (!string.IsNullOrEmpty(AddDateFrom) && !string.IsNullOrEmpty(AddDateTo))
            {
                ItemCodeSQL = QueryOperatorsEnumHelper.ConvertCommonOperator("AddDate", QueryOperatorsEnum.范围, AddDateFrom + " 00:00:00|" + AddDateTo + " 23:59:59");
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + ItemCodeSQL;
                }
                else
                {
                    wheresql = ItemCodeSQL;
                }
            }

            if (!string.IsNullOrEmpty(MacType))
            {
                ItemCodeSQL = string.Format(" (MacType = '{0}') ", MacType);
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + ItemCodeSQL;
                }
                else
                {
                    wheresql = ItemCodeSQL;
                }
            }

            if (!string.IsNullOrEmpty(SCDATEFrom) && !string.IsNullOrEmpty(SCDATETo))
            {
                ItemCodeSQL = QueryOperatorsEnumHelper.ConvertCommonOperator("SCDATE", QueryOperatorsEnum.范围, SCDATEFrom + "|" + SCDATETo);
                if (!string.IsNullOrEmpty(wheresql))
                {
                    wheresql += " and " + ItemCodeSQL;
                }
                else
                {
                    wheresql = ItemCodeSQL;
                }
            }
            return wheresql;
        }
    }
}